package com.bootmybatisdemo.demo.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class RequestUtils {

    /**
     * 获取request请求的token值
     * @return
     */
    public static String loginToken(){
        HttpServletRequest request= ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String jwtToken = request.getHeader("jwtToken");
        if(StringUtils.isNotEmpty(jwtToken)){
            return jwtToken;
        }
        return null;
    }

    /**
     * 获取请求request值
     * @return
     */
    public static HttpServletRequest apiRequest(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }
}
